package com.affectu.news.action;

import java.util.List;

import org.hibernate.HibernateException;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.datamodel.DataModel;

import com.affectu.dao.DAOBase;
import com.affectu.news.News;

/**
 * 2008-8-8
 * 
 * @author daniel zhang
 * 
 */
@Name("newsAction")
public class NewsAction extends DAOBase {

	@In
	private News news;

	@SuppressWarnings("unused")
	@DataModel
	private List<News> allNews;

	public NewsAction() {

	}

	@SuppressWarnings("unchecked")
	public boolean addNews() {
		boolean flag = false;
		try {
			em.persist(news);
			allNews = em.createQuery("from News").list();
			em.flush();
			// em.beginTransaction().commit();
			flag = true;
		} catch (HibernateException e) {
			e.printStackTrace();
		}
		return flag;
	}

	@SuppressWarnings("unchecked")
	public List<News> getAllNews() {
		return em.createQuery("from News").list();
	}
}
